# values from parrot_config
BUILD_DIR     = @build_dir@
LOAD_EXT      = @load_ext@
O             = @o@
EXE           = @exe@
PERL          = @perl@
RM_F          = @rm_f@

# Various paths
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PERL6GRAMMAR  = $(BUILD_DIR)/runtime/parrot/library/PGE/Perl6Grammar.pbc
NQP           = $(BUILD_DIR)/compilers/nqp/nqp.pbc
PCT           = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc

# Setup some commands
PARROT        = $(BUILD_DIR)/parrot$(EXE)
PBC_TO_EXE    = $(BUILD_DIR)/pbc_to_exe$(EXE)

SOURCES = dectest.pir \
  src/gen_grammar.pir \
  src/gen_actions.pir

# PMCS        = dectest
# PMC_SOURCES = $(PMC_DIR)/dectest.pmc
# DECTEST_GROUP  = $(PMC_DIR)/dectest_group$(LOAD_EXT)

CLEANUPS = \
  dectest.pbc \
  dectest.c \
  *.pdb \
  dectest$(O) \
  dectest$(EXE) \
  src/gen_*.pir \
  src/gen_*.pm

# the default target
all: dectest$(EXE)

##  targets for building a standalone executable
dectest$(EXE): dectest.pbc
	$(PBC_TO_EXE) dectest.pbc

# the compiler .pbc
dectest.pbc: Makefile $(PARROT) $(SOURCES) $(BUILTINS_PIR)
	$(PARROT) $(PARROT_ARGS) -o dectest.pbc dectest.pir

src/gen_grammar.pir: $(PARROT) $(PERL6GRAMMAR) src/pct/grammar.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/gen_grammar.pir \
	    src/pct/grammar.pg

src/gen_actions.pir: $(PARROT) $(NQP) $(PCT) src/pct/actions.pm
	$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
	    --encoding=fixed_8 --target=pir src/pct/actions.pm

##  cleaning
clean:
	$(RM_F) $(CLEANUPS)
